Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User 서버 request 변경에 따른 수정사항 반영, 댓글 달기 및 조회 API #4

Merged
merged 5 commits into from
Sep 5, 2023

Conversation

jjunjji
Copy link
Member

@jjunjji jjunjji commented Sep 5, 2023

🔥 Summary

  • User 서버 requeset 변경 반영
  • 게시글 상세보기, 게시글에 달린 댓글 조회 API
  • 댓글 달기 API

✏️ Describe your changes

  • User 서버의 커뮤니티 회원 조회가 기존의 RequestBody -> QueryParms로 변경되면서 List로 받았던 userIdListString으로 변경하는 작업이 필요했습니다. List의 각 원소를 ','로 join하여 String으로 만들어 uri를 빌드할 때 추가했고, 코드 리뷰를 통해 알게된 onStatus에서 response의 상태를 확인하여 예외처리를 할 수 있도록 변경했습니다.

    public List<CommunityUserInfo> sendCommunitiesInfoRequest(String token, List<Long> userIdList) {
    String param = userIdList.stream()
    .map(String::valueOf)
    .collect(Collectors.joining(","));
    log.warn(LOG_FORMAT, param);
    return webClient.get()
    .uri(uriBuilder -> uriBuilder.path("/communities/info").queryParam("userIdList", param).build())
    .header("Authorization", token)
    .retrieve()
    .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new TokenException()))
    .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new UserBadGateWayException()))
    .bodyToMono((new ParameterizedTypeReference<BaseResponse<Map<String, List<CommunityUserInfo>>>>() {
    }))
    .map(response -> response.getData().get("communityUserInfoBlocks"))
    .block();
    }

  • 다른 request들도 변경 사항에 맞게 수정하였고, 동일하게 onStatus도 적용했습니다..!

    public Long getUserId(String token) {
    return sendTokenMeRequest(token).getUserId();
    }
    private UserInfo sendTokenMeRequest(String token) {
    return webClient.get()
    .uri("/token/me")
    .header("Authorization", token)
    .retrieve()
    .onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new TokenException()))
    .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new UserBadGateWayException()))
    .bodyToMono((new ParameterizedTypeReference<BaseResponse<UserInfo>>() {
    }))
    .map(BaseResponse::getData)
    .block();
    }

  • 게시글 상세보기와 댓글 조회가 하나의 API로 합쳐져 있었는데 response 가독성이 너무 좋지 않았고, 로직 또한 복잡해져서 피드백을 받아 각각을 조회하는 API를 분리했습니다.
    image
    image

📖Review Point

@jjunjji jjunjji merged commit f3db540 into main Sep 5, 2023
@jjunjji jjunjji deleted the fix/userRequest branch September 6, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant